home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-18 | 5.9 KB | 198 lines | [TEXT/ALFA] |
- #############################################################################
- # Install the files that support one of the LaTeX modes.
- # The global flag $latexVersion indicates which mode (LaTeX 2.09 or LaTeX2e)
- # is currently installed.
- #
- # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
- #
- proc loadLaTeX {} {
- global HOME latexVersion
-
- set oldWd [pwd]
- cd $HOME
-
- set latex209Dir ":LaTeX:latex 2.09"
- set latex209Files {
- {"latex.tcl" ":Tcl:SystemCode"}
- {"latexMode.tcl" ":Tcl:SystemCode"}
- {"LaTeX Help" ":Help"}
- {"LaTeX Key Bindings" ":Help"}
- }
- set latex2eDir ":LaTeX:latex 2e"
- set latex2eFiles {
- {"latex.tcl" ":Tcl:SystemCode"}
- {"latexKeys.tcl" ":Tcl:SystemCode"}
- {"latexMenu.tcl" ":Tcl:SystemCode"}
- {"latexMode.tcl" ":Tcl:SystemCode"}
- {"LaTeX Help" ":Help"}
- {"LaTeX Key Bindings" ":Help"}
- }
- set report 0
-
- if {$latexVersion == "2e"} {
- if {[askyesno "Install LaTeX 2.09?"] == "yes"} {
- set report [installFiles $latex209Dir $latex209Files $latex2eDir $latex2eFiles 1 TeX]
- if {$report != 0} {
- # uncomment these lines if new files are not automatically sourced
- # alertnote "Now quit and restart Alpha to load LaTeX 2.09 mode"
- # set latexVersion "2.09"
- # and comment out this one
- alertnote "LaTeX 2.09 support was successfully installed"
- #
- } else {
- alertnote "The installation was cancelled"
- }
- }
- } elseif {$latexVersion == "2.09"} {
- if {[askyesno "Install LaTeX 2e?"] == "yes"} {
- set report [installFiles $latex2eDir $latex2eFiles $latex209Dir $latex209Files 1 TeX]
- if {$report != 0} {
- # uncomment these lines if new files are not automatically sourced
- # alertnote "Now quit and restart Alpha to load LaTeX2e mode"
- # set latexVersion "2e"
- # and comment out this one
- alertnote "LaTeX2e support was successfully installed"
- #
- } else {
- alertnote "The installation was cancelled"
- }
- }
- }
-
- if {$report != 0} {
- set timePat {([0-9/]+) ([^:]+):([^:]+):([^:]+) (..)}
- regsub $timePat [join [mtime [now] short]] {\1 \2.\3\5} timestamp
- set fname "$HOME:LaTeX:Install Report $timestamp"
-
- set tmpfid [open $fname "w+"]
- puts $tmpfid $report
- close $tmpfid
- }
-
- cd $oldWd
- }
-
- ##############################################################################
- # Install a list of files from $InstallDir into various destination folders.
- #
- # Each item of $installList contains a list of two items : a file and its
- # destination directory. If $backupDir and $backupList are given, then the
- # files from this list are first removed from the indicated directories and
- # saved in $backupDir. If $deleteOld is 1, then an old file is just
- # deleted if the backup directory doesn't exist or if it already contains
- # the file.
- #
- # If any Tcl source files (.tcl) are installed, then they are also automatically
- # sourced and "rebuildTclIndices" is called to update the autoloader index files.
- #
- # Author: Tom Pollard <pollard@cucbs.chem.columbia.edu>
- #
- proc installFiles {installDir installList backupDir backupList
- {deleteOld 0} {deleteBindings 0}} {
- global HOME
- set script {}
- set report ""
- set askedAlready 0
-
- set script2 {}
- set report2 ""
-
- if {! [file exists $backupDir] && ! $deleteOld} {
- lappend script [list mkdir $backupDir]
- append report "Created backup directory \"$backupDir\"\n"
- }
-
- foreach item $backupList {
- set file [lindex $item 0]
- set dir [lindex $item 1]
-
- set frompath ${dir}:${file}
- set topath ${backupDir}:${file}
-
- if {[file exists $frompath]} {
- if {[file exists $topath]} {
- if {!$deleteOld && !$askedAlready} {
- if {[askyesno "Can I delete old files that are already backed up?"] == "yes"} {
- set deleteOld 1
- }
- set askedAlready 1
- }
- if {$deleteOld} {
- lappend script [list removeFile $frompath]
- append report "Deleted old file \"$file\" from folder \"$dir\"\n"
-
- } elseif {[askyesno "Overwrite old backup file \"$file\"?"] == "yes"} {
- lappend script [list removeFile $topath]
- lappend script [list moveFile $frompath $topath]
- append report "Saved old file \"$file\" in folder \"$dir\"\n"
-
- } else {
- message "No files were moved or deleted"
- return 0
- }
- } else {
- lappend script [list moveFile $frompath $topath]
- append report "Saved old file \"$file\" in folder \"$backupDir\"\n"
- }
- } else {
- append report "-- old file \"$file\" was missing from folder \"$dir\" --\n"
- }
- }
-
- append report "\n"
-
- foreach item $installList {
- set file [lindex $item 0]
- set dir [lindex $item 1]
- set frompath ${installDir}:${file}
- set topath ${dir}:${file}
-
- if {[file exists $frompath]} {
- lappend script [list copyFile $frompath $topath]
- append report "Copied file \"$file\" from folder \"$installDir\" to \"$dir\"\n"
-
- if {[file extension $file] == ".tcl"} {
- lappend script2 [list uplevel {#0} [list source ${HOME}$topath]]
- append report2 "Loaded the new file \"$file\"\n"
- }
- } else {
- message "Installation aborted - no files were moved or deleted"
- alertnote "Install file \"$file\" is missing"
- return 0
- }
- }
-
- if {[llength $script2]} {
- # comment out these lines to stop automatic sourcing of newly loaded .tcl files
- # (_Don't_ change the lines creating $script2, above)
- if {$deleteBindings != 0} {
- lappend script [list deleteModeBindings $deleteBindings]
- append report "\nRemoved the old ${deleteBindings}-mode key bindings\n"
- }
- set script [concat $script $script2]
- append report "\n"
- append report $report2
- #
- lappend script [list rebuildTclIndices]
- append report "\nUpdated the auto-loader index files\n"
- }
-
- # # Uncomment these lines to get a play-by-play of the installation procedure
- # #
- # new -n "* Install Script *"
- foreach item $script {
- # insertText "$item\n"
- eval $item
- }
- # catch {shrinkWindow 1}
- # setWinInfo dirty 0
-
- new -n "* Installation Report *"
- insertText $report
- catch {shrinkWindow 1}
- setWinInfo dirty 0
- setWinInfo read-only 1
-
- return $report
- }
-